lyfdefine(function () {
    return ({
        data: function () {
            return {
                dataForm: {
                    opSource: '',
                    opStatus: '',
                    creatorName: '',
                    dateRange: '',
                    startTime: '',
                    endTime: ''
                },
                checkList: [],
                dataList: [],
                dataListLoading: false,
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                chooseDate: [],              // 选择日期
                queryAreaVisible: true,
                dataResourceArr: {
                    "1": "直营预测--执行",
                    "2": "直营预测计划--门店",
                    "3": "直营准确率",
                    "4": "直营差异",
                    "5": "直营预测计划",
                    "6": "需求计划",
                    "7": "销售额目标",
                    "8": "其他渠道计划",
                    "9": "其他渠道计划差异",
                    "10": "其他渠道计划准确率"
                },
                dataStatusArr: {
                    "0": "处理中",
                    "1": "成功",
                    "2": "失败",
                    "3": "已删除"
                }
            }
        },
        mounted() {
            this.getDataList();
        },
        methods: {
            getDataList() {
                this.dataListLoading = true;
                this.dataForm.pageSize = this.pageSize;
                this.dataForm.pageNum = this.pageIndex;
                if (this.dataForm.dateRange) {
                    this.dataForm.startTime = this.dataForm.dateRange[0]
                    this.dataForm.endTime = this.dataForm.dateRange[1]
                }
                this.$http({
                    url: "/scm-plan-admin/api/v1/operationLogRecord/getOperationLogs",
                    method: 'post',
                    data: this.dataForm
                }).then(result => {
                    var data = result.data;
                    if (data && data.code === '0') {
                        this.dataList = data.data.list;
                        this.totalPage = data.data.total
                    } else {
                        this.dataList = [];
                        this.totalPage = 0
                    }
                    this.dataListLoading = false
                }).catch(reason => {
                    /*如果出现了异常，页面停止旋转*/
                    this.dataListLoading = false;
                    /*弹出提示框*/
                    this.$message.error("加载失败");
                })
            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val;
                this.pageIndex = 1;
                this.getDataList();
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val;
                this.getDataList();
            },
            // 重置
            clearCondition() {
                this.dataForm = {};
            },
            deleteByMark(scope) {
                let ids = []
                ids.push(scope.row.id)
                //将状态变为处理中
                this.$http({
                    url: 'scm-plan-admin/api/v1/operationLogRecord/opLog/Initiating',
                    method: 'post',
                    data: ids
                }).then(result => {
                    let data = result.data;
                    if (data && data.code === '0') {
                        this.$message.success("处理中");
                        this.getDataList();
                        let values = []
                        values.push(scope.row)
                        this.rmByOpSign(values);
                    } else {
                        this.$message.error(data.msg);
                    }
                }).catch(reason => {
                    this.$message.error("删除失败");
                })
            },
            rmByOpSign(values) {
                this.$http({
                    url: 'scm-plan-admin/api/v1/operationLogRecord',
                    method: 'delete',
                    data: values
                }).then(result => {
                    let data = result.data;
                    if (data && data.code === '0') {
//TODO 这里长时间是获取不到响应的，怎么做合适
                    } else {
                        if (data.msg) {
                            this.$message.error(data.msg);
                        } else {
                            this.$message.error("处理失败");
                        }
                    }
                })
            },
            reRunTask() {
                alert("重新执行定时任务")
            },
            handleBigData() {
                this.$http({
                    url: 'scm-plan-admin/api/v1/operationLogRecord/bigData/Initiating',
                    method: 'POST',
                }).then(result => {
                    let data = result.data;
                    if (data && data.code === '0') {
                        this.$message.success("处理中");
                        this.getDataList();
                        this.remedyBigDataJob();
                    } else {
                        this.$message.error(data.msg);
                    }
                })
            },
            remedyBigDataJob() {
                this.$http({
                    url: 'scm-plan-admin/api/v1/bigData/generalHandler/remedy',
                    method: 'POST',
                }).then(result => {
                    let data = result.data;
                    if (data && data.code === '0') {
//TODO 这里长时间是获取不到响应的，怎么做合适
                    } else {
                        if (data.msg) {
                            this.$message.error(data.msg);
                        } else {
                            this.$message.error("处理失败");
                        }
                    }
                })
            },
            batchDelete() {
                if(!this.checkList.length){
                    return
                }
                let ids = []
                this.checkList.forEach(item => {
                    ids.push(item.id)
                })
                //将状态变为处理中
                this.$http({
                    url: 'scm-plan-admin/api/v1/operationLogRecord/opLog/Initiating',
                    method: 'post',
                    data: ids
                }).then(result => {
                    let data = result.data;
                    if (data && data.code === '0') {
                        this.$message.success("处理中");
                        this.getDataList();
                        this.rmByOpSign(this.checkList);
                    } else {
                        this.$message.error(data.msg);
                    }
                }).catch(reason => {
                    this.$message.error("删除失败");
                })
            },
            handleSelection(row, index) {
                if (row.opStatus === 1)
                    return true
                else
                    return false
            },
            selectionRowsChange(value) {
                this.checkList = value
            }
        },
        template: `
<div class="mod-config">
<el-card class="box-card search-input" shadow="never">
    <div slot="header">
        <span >数据管理</span>
    </div>
    <el-form label-width="100px" ref="dataForm" :model="dataForm" :inline="true" size="mini" @keyup.enter.native="getDataList()">
        <el-row>
                <el-form-item label="数据源">
                    <el-select v-model="dataForm.opSource"
                        clearable
                        filterable
                        placeholder="选择数据源">
                        <el-option
                            v-for="(value,key) in dataResourceArr"
                            :key="key"
                            :label="value"
                            :value="key">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="状态">
                    <el-select v-model="dataForm.opStatus"
                        clearable
                        filterable
                        placeholder="选择状态">
                        <el-option
                            v-for="(value,key) in dataStatusArr"
                            :key="key"
                            :label="value"
                            :value="key">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="操作人">
                    <el-input v-model="dataForm.creator" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="时间段">
                    <el-date-picker
                    value-format="yyyy-MM-dd HH:mm:ss"
      v-model="dataForm.dateRange"
      type="datetimerange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期">
    </el-date-picker>
                </el-form-item>
        </el-row>
               <el-row>
                  <el-col :span="3" style="float: right;margin-right: -85px">
                       <el-button type="success" size="mini" @click="handleBigData">处理</el-button>
                     <el-tooltip class="item" effect="light" placement="top-start">
            <i class="el-icon-info" />
            <div slot="content">补救前一次大数据处理异常的结果<br/>时间段：00:00 —— 20:00</div>
          </el-tooltip>
</el-col>
 <el-col :span="1" style="float: right">
                    <el-button type="danger" size="mini" @click="batchDelete" >删除</el-button>
                       </el-col>
            <el-col :span="3" style="float: right">
                    <el-button type="primary" size="mini" @click="getDataList()" >查询</el-button>
                    <el-button type="primary" size="mini" @click="clearCondition()">重置</el-button>
                       </el-col>
                   
        </el-row>
    </el-form>
    </el-card>
<!--    数据列表-->
    <el-card class="box-card"> 
        <el-table @selection-change="selectionRowsChange" :data="dataList" :header-cell-style="{'text-align':'center'}" v-loading="dataListLoading" highlight-current-row="true" size="mini" border="true"
    style="width: 100%">
         <el-table-column
         :selectable="handleSelection"
      type="selection"
      width="40">
    </el-table-column>
            <el-table-column fixed="left" label="操作" width="60">
              <template slot-scope="scope">
                <el-button v-if="scope.row.opStatus === 1" @click="deleteByMark(scope)" type="text" size="mini">删除</el-button>
<!--                <el-button @click="reRunTask()" type="text" size="mini">执行</el-button>-->
              </template>
            </el-table-column>
            <el-table-column prop="opContent" label="操作日志" width="160"></el-table-column>
              <el-table-column prop="opSource" label="操作数据源" width="160">
            <template slot-scope="scope">
                            <span>{{dataResourceArr[scope.row.opSource]}}</span>
                        </template>
            </el-table-column>
            <el-table-column prop="opSign" label="操作标识" width="160"></el-table-column>
            <el-table-column prop="opStatus" label="操作状态" width="120">
            <template slot-scope="scope">
                            <span>{{dataStatusArr[scope.row.opStatus]}}</span>
                        </template>
            </el-table-column>
            <el-table-column prop="opTime" label="操作用时" width="120">
                <template slot-scope="scope">
                            <span>{{scope.row.opTime == '0ms' ? '-' : scope.row.opTime}}</span>
                        </template>
</el-table-column>
            <el-table-column prop="opAmount" label="操作数量" width="120">
             <template slot-scope="scope">
                            <span>{{scope.row.opAmount}}</span>
                        </template>
</el-table-column>
              <el-table-column prop="createTime" label="操作日期" width="160"></el-table-column>
            <el-table-column prop="creatorName" label="操作人" width="120"></el-table-column>
             <el-table-column prop="failReason" label="异常原因" width="800"></el-table-column>
        </el-table>
        <el-pagination
                @size-change="sizeChangeHandle"
                @current-change="currentChangeHandle"
                :current-page="pageIndex"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                :total="totalPage"
                layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
    </el-card>
</div>        
`
    })
})
